var images = document.getElementsByTagName('img');
var len = images.length;
for (var i=0; i<len; i++){
   var img = images.item(i);
   img.onclick = function(event){alert(img.getAttribute('alt'));}
}